AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')

function ENT:Initialize()
	self:DrawShadow( false )
	
end

function ENT:SpawnEntity( ply )

	if self.TargetClass == nil then
		Error( self:GetClass() .. " does not have a target class to spawn a block" ) 
	end
	
	local Ent = ents.Create( self.TargetClass )
	
	if !ValidEntity( Ent ) then
		Error( self.TargetClass .. " entity could not be created!")
		return
	end
	
	Ent:SetAngles( self:GetAngles() )
	Ent:SetPos( self:GetPos() )
	Ent:Spawn()	
	
	Ent:SetSpawner( ply )
	
	hook.Call("BlockSpawn", GAMEMODE, ply, Ent )
	
end	

function ENT:CanSpawn( ply )
	return hook.Call("AllowSpawnBlock", GAMEMODE, ply, self ) != false
end

function ENT:KeyValue( key, value )

end

function ENT:AcceptInput( name, activator, caller, data )
    
	if EntityDebug then
		print("Input on ent_block_spawner ", Game.State(), name, activator, caller, data )
	end
	
	if Game.State() != Game.BUILD then
		return
	end
	
	if name == "Spawn" && self:CanSpawn( activator ) then 
        self:SpawnEntity( activator )
    end
	
end
